<template>
	<view class="content">
		<!-- <view class="info">
			<view class="info1">
				<text>姓名</text>
				<input type="text" v-model="nm" value="" placeholder="请输入姓名" placeholder-class="inputStyle" />
			</view>
			<view class="info1">
				<text>手机号</text>
				<input type="number" v-model="phnNum" value="" placeholder="请输入手机号" placeholder-class="inputStyle" @ />
			</view>
			<view class="info1">
				<text>故障原因</text>
				<input type="text" v-model="causeOfIssue" value="" placeholder="请输入故障原因" placeholder-class="inputStyle" />
			</view>
			<view class="info1" @click="getMap">
				<text>故障地点</text>
				<input type="text" v-model="faultLocation" disabled value="" placeholder="请输入故障地点" placeholder-class="inputStyle" />
			</view>
		</view>
		<view class="idCrd">
			<text style="margin-bottom: 20rpx;">故障图片</text>
			<view class="ddd">
				<view v-for="(item, index) in tempFilePaths" :key="index" v-if="tempFilePaths">
					<view class="image" @click="changeImg(index)"><image :src="item" mode="aspectFill"></image></view>
				</view>
				<view class="image" @click="shanchuan"><u-icon name="plus" color="#ccc" size="50"></u-icon></view>
			</view>
		</view>

		<view class="confirmUpload" @click="confirmUp">确认上传</view> -->
		<view class="ddd"><button open-type="contact" class="u-reset-button butt" style="width: 100%; height: 100%;">联系客服</button></view>
	</view>
</template>

<script>
import uploadImage from '../../../common/ossutil/uploadFile.js';
export default {
	data() {
		return {
			nm: '', // 姓名
			phnNum: '', // 手机号码
			causeOfIssue: '', //  故障原因
			faultLocation: '', //  故障地点

			tempFilePaths: [],
			data: {},
			oid: ''
		};
	},
	onLoad(e) {
		this.oid = e.oid;
	},
	methods: {
		async getMap() {
			
				const res = await uni.chooseLocation();
				this.faultLocation = res[1].address
				
				console.log('res',res);
			
		},
		
		
		shanchuan() {
			uni.chooseImage({
				count: 1,
				sourceType: ['album'],
				success: res => {
					uni.showLoading({
						mask: true
					});

					uploadImage(res.tempFilePaths[0], 'images/', result => {
						this.tempFilePaths.push(result);
						uni.hideLoading();
					});
				}
			});
		},

		success1() {
			this.shanchuan();
		},
		changeImg(i) {
			uni.chooseImage({
				count: 1,
				sourceType: ['album'],
				success: res => {
					uni.showLoading({
						mask: true
					});

					uploadImage(res.tempFilePaths[0], 'car/', result => {
						this.tempFilePaths[i] = result;
						let tempFilePaths = this.tempFilePaths;
						this.tempFilePaths = [];
						this.tempFilePaths = tempFilePaths;
						console.log('this.tempFilePaths :>> ', this.tempFilePaths);
						uni.hideLoading();
					});
				}
			});
		},

		async confirmUp() {
			let list = [this.nm, this.phnNum, this.faultLocation, this.causeOfIssue];
			if (!this.nm || !this.phnNum || !this.faultLocation || !this.causeOfIssue) return uni.$showMsg('不能为空');

			const res = await this.$u.post('api/car/vehicle_failure', {
				uid: uni.getStorageSync('uid'),
				oid: this.oid,
				name: this.nm,
				phone: this.phnNum,
				site: this.faultLocation,
				cause: this.causeOfIssue,
				imgs: this.tempFilePaths
			});
			console.log('res >>  ', res);
			uni.reLaunch({
				url: '../order'
			});
			uni.$showMsg(res.msg);
		}
	}
};
</script>

<style lang="scss" scoped>
.content {
	.ddd {
		position: absolute;
		left: 50%;
		bottom: 150rpx;
		transform: translateX(-50%);
		width: 670rpx;
		height: 90rpx;
		background: #2a2929;
		border-radius: 10rpx;
		margin: 0 auto;
		display: flex;
		align-items: center;
		color: #ffffff;
		font-size: 35rpx;
		justify-content: center;
		letter-spacing: 10rpx;
	}
	.butt {
		display: flex;
		align-items: center;
		justify-content: center;
	}
	width: 100vw;
	height: 100vh;
	overflow: scroll;
	padding: 30rpx;
	.info {
		width: 690rpx;
		//height: 689rpx;
		background: #2a2929;
		box-shadow: 0rpx 0rpx 18rpx 0rpx rgba(51, 51, 51, 0.1);
		border-radius: 20rpx;
		padding: 25rpx 31rpx 31rpx 31rpx;
		margin: 0 auto;

		.info1 {
			display: flex;
			flex-direction: column;
			justify-content: center;
			height: 131rpx;
			// margin-left: 29rpx;
			border-bottom: 2rpx solid #f1eded;

			text {
				font-size: 36rpx;
				font-family: 'Microsoft YaHei', PingFang SC;
				font-weight: 400;
				color: #ffffff;
			}

			text:before {
				content: '*';
				color: #ff0000;
			}

			.inputStyle {
				font-size: 30rpx;
				font-family: 'Microsoft YaHei', PingFang SC;
				font-weight: 400;
				color: #ffffff;
			}
			input {
				color: #ffffff;
				padding-left: 10rpx;
			}
		}
	}

	.idCrd {
		width: 690rpx;
		//height: 300rpx;
		background: #2a2929;
		border-radius: 20rpx;
		padding: 30rpx;
		margin-top: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		.ddd {
			display: flex;
			//justify-content: flex-start;
			flex-wrap: wrap;
			//padding: 0  30rpx;
			image {
				width: 100%;
				height: 100%;
			}
			.image {
				width: 250rpx;
				height: 180rpx;
				border: 1rpx dashed #606266;
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-left: 40rpx;
				margin-bottom: 20rpx;
			}
		}

		text {
			height: 34rpx;
			line-height: 34rpx;
			font-size: 36rpx;
			font-family: 'Microsoft YaHei', PingFang SC;
			font-weight: 400;
			color: #ffffff;
		}

		text:before {
			content: '*';
			color: #ff0000;
		}
		/deep/ .u-list-item {
			background: none !important;
			border: 1rpx dashed #606266;
			margin-right: 30rpx !important;
		}
		/deep/ .u-upload {
			// display: flex !important;
			// justify-content: space-between !important;
		}
	}
	.confirmUpload {
		margin: 0 auto;
		margin-top: 99rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690rpx;
		height: 100rpx;
		background: #d60000;
		border-radius: 50rpx;

		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
	}
}
</style>
